@tool
class_name Detector_Selection
extends Detector

#region 属性
@export var selection_mode:GameEnum.DetectorSelectMode
var targets:Array = []
#endregion
#region 字段
#endregion
#region 信号
#endregion

#region 基类方法
func init(entity:Entity,args:Dictionary = {}) -> bool:
	if super.init(entity):
		return true
	return false
func set_enable(enable:bool):
	if enable and not self.enable:
		pass
	elif not enable and self.enable:
		pass
func update(delta:float) -> bool:
	if super(delta):
		return true
	return false
func destroy():
	super()
#endregion
#region 公共方法
func get_selection(args:Dictionary = {}):
	match selection_mode:
		GameEnum.DetectorSelectMode.Mouse:
			return get_global_mouse_position()
		GameEnum.DetectorSelectMode.TargetAroundTheMouse:
			# TODO 返回鼠标附近的Target，具体参数通过args传递
			pass
		GameEnum.DetectorSelectMode.ClosedTarget:
			var detector_component:DetectComponent = entity.get_component(DetectComponent)
			if not detector_component:
				return null
			var detector:Detector_Target = detector_component.get_detector(GameEnum.DetectorType.Target)
			if not detector:
				return null
			return detector.get_closed_target(entity.root.global_position,args.get("FilterFunc",null),args.get("Count",1))
		GameEnum.DetectorSelectMode.ByOtherSystem:
			return targets
		_:
			pass
#endregion
#region 私有方法
#endregion
#region 生命周期函数
func _enter_tree() -> void:
	detector_type = GameEnum.DetectorType.Selection
#endregion
